package org.glut.wechat.moments.controller;

import cn.hutool.core.io.FileUtil;
import org.glut.wechat.moments.utils.AliOSSUtils;
import org.glut.wechat.moments.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

@CrossOrigin
@RestController
public class UploadController {

    @Autowired
    private AliOSSUtils aliOSSUtils;

    @PostMapping(value = "/upload")
    public Result upload(@RequestPart(value = "file") MultipartFile multipartFile) throws IOException {
        String url = aliOSSUtils.upload(multipartFile);
        return Result.ok("上传成功",url);
    }

}
